package com.igeek.d0618.test2;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

/**
 * @Author: zhiyu
 * @Date:18:24
 * @DESC:
 */
public class ListDemo {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class<ArrayListInt> arrayListIntClass = ArrayListInt.class;
        ArrayListInt arrayListInt = arrayListIntClass.newInstance();
        ArrayList<Integer> list = arrayListInt.getList();
        Class<? extends ArrayList> aClass = list.getClass();
        Method add = aClass.getMethod("add", Object.class);
        add.invoke(list,"string");
        System.out.println(list);
    }

}
class ArrayListInt{
    private ArrayList<Integer> list = new ArrayList();

    public ArrayList<Integer> getList() {
        return list;
    }

    public void setList(ArrayList<Integer> list) {
        this.list = list;
    }
}